﻿#include <QStringList>
#include <QDateTime>
#include "TreeItem.h"
#include <QDebug>
TreeItem::TreeItem(TreeItem *parent)
{
    m_ParentItem = parent;
    m_DataPtr = NULL;
    m_CurrNode = 0;
    m_Row = 0;
}

TreeItem::~TreeItem()
{
    if(this->childCount()!=0){
        clearChilds();
    }
}

void TreeItem::appendChild(TreeItem *item)
{
    item->setRow(m_ChildItemList.size());   //item存自己是第几个，可以优化效率
    m_ChildItemList.append(item);
}

void TreeItem::clearChilds()
{
    qDeleteAll(m_ChildItemList);
    m_ChildItemList.clear();
}

TreeItem *TreeItem::child(int row)
{
    return m_ChildItemList[row];
}

TreeItem *TreeItem::parentItem()
{
    return m_ParentItem;
}

int TreeItem::childCount() const
{
    return m_ChildItemList.count();
}

int TreeItem::row() const
{
    return m_Row;
}

QVariant TreeItem::data(int column) const
{
    if(m_CurrNode >= 0 )
    {
        //一级节点返回数据
        if(column == 0&&m_DataPtr!=nullptr)
        {
            _DATA_STRUCT* data = (_DATA_STRUCT*)m_DataPtr;
            return data->strFileName;
        }

    }
      return QVariant();
}




